#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <signal.h>

static void timer_handler(int signum)
{
    printf ("timerover %d\n", (int) time((time_t*) NULL));
}

static void init_sigaction(void)
{
    int ret;
    struct sigaction act;
    act.sa_handler=timer_handler;
    act.sa_flags=0;
    sigemptyset(&act.sa_mask);
    ret = sigaction(SIGALRM, &act, NULL);
    if(ret != 0)
        perror("sigaction");
}

static void init_timer(void)
{
    int ret;
    struct itimerval value, old_value;
    value.it_value.tv_sec=1;
    value.it_value.tv_usec=0;
    value.it_interval=value.it_value;

    ret = setitimer(ITIMER_REAL, &value, &old_value); 
    if (ret != 0) 
        perror("setitimer");
}

int main(int argc, char** argv)
{
	init_sigaction();
	init_timer();

	while(1) {
		sleep(1000);
	}

	return 0;
}
